package com.zx.mes.hyl.upms.dao;

import com.zx.mes.hyl.upms.model.Trole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author hyl
 * @date 2017-11-25
 */
public interface RoleRepository extends JpaRepository<Trole,String>,JpaSpecificationExecutor<Trole> {
    @Query("select distinct t from Trole t left join fetch t.tresources resource where t.id = :id")
    Trole getById(@Param("id") String id);

    @Query("select distinct t from Trole t left join fetch t.tresources resource join fetch t.tusers user where user.id = :userId order by t.seq")
    List<Trole> findByUserId(@Param("userId") String userId);

    @Query("select distinct t from Trole t join fetch t.tusers user where user.id = :userId order by t.seq")
    List<Trole> findAllRoleByUserId(@Param("userId") String userId);
}

